import 'package:flutter_demo/entities/article_item.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';

class FavListController extends GetxController {
  static const kFavListKey = "search_history_list";

  final favList = [].val("kFavListKey");

  addFav(ArticleItem item) {
    final list = favList.val;
    list.add(item.toJson());
    favList.val = list;
    update();
  }

  removeFav(ArticleItem item) {
    final list = favList.val;
    list.removeWhere((element) => element["link"] == item.link);
    favList.val = list;
    update();
  }

  bool isFav(ArticleItem item) {
    final list = favList.val;
    return list.indexWhere((element) => element["link"] == item.link) != -1;
  }
}